package com.itheima.dubbo.mongodb.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.commons.pojo.FollowUser;
import com.itheima.commons.pojo.Video;
import com.itheima.commons.vo.PageResult;
import com.itheima.dubbo.interfaces.VideoApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

/**
 * @Author: lqTao
 * @Date: 2021/12/11 13:40
 */
@Service
public class VideoApiImpl implements VideoApi {

    @Autowired
    MongoTemplate mongoTemplate;

    @Override
    public void followUser(FollowUser followUser) {
        mongoTemplate.save(followUser);

    }

    @Override
    public void disFollowUser(FollowUser followUser) {
        mongoTemplate.remove(Query.query(Criteria.where("userId").is(followUser.getUserId())
                        .and("followUserId").is(followUser.getFollowUserId()))
                , FollowUser.class);
    }

    @Override
    public Boolean isFollowUser(Long userId, Long followUserId) {
        return null;
    }

    @Override
    public void saveVideo(Video video) {
        mongoTemplate.save(video);
    }

}
